package com.nanhang.auth.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nanhang.auth.Uo.UserUo;
import com.nanhang.auth.entity.User;
import com.nanhang.auth.entity.UserLogin;
import com.nanhang.auth.mapper.Usermapper;
import com.nanhang.auth.service.IUserservice;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class Userserviceimpl extends ServiceImpl<Usermapper, User> implements IUserservice {

    @Override
    public UserLogin findUser(UserUo uo) {
        UserLogin loginUser = new UserLogin();
        String token = UUID.randomUUID().toString();
        loginUser.setToken(token);
        User user = this.getOne(new QueryWrapper<User>().eq("username", uo.getUsername()));

        String pwd = SecureUtil.md5(uo.getPassword());
        if (pwd.equals(user.getPassword())) {
            loginUser.setUser(user);
            return loginUser;
        }
        return null;
    }
}
